package com.java.module.cms.controller.admin;

import java.util.List;

import com.java.common.lang.annotation.Log;
import com.java.common.lang.domain.AjaxResult;
import com.java.common.lang.domain.page.TableDataInfo;
import com.java.common.lang.enums.BusinessTypeEnum;
import com.java.common.utils.WebKit;
import com.java.common.utils.poi.ExcelUtil;
import com.java.module.cms.domain.Banner;
import com.java.module.cms.service.IBannerService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 基础：banner图Controller
 *
 * @author Administrator
 * @date 2021-03-22
 */
@RestController("AdminBannerController")
@RequestMapping("/cms/banner")
public class BannerController {

    @Autowired
    private IBannerService bannerService;

    /**
     * 查询基础：banner图列表
     */
    @PreAuthorize("@ss.hasPermi('cms:banner:list')")
    @GetMapping("/list")
    public TableDataInfo list(Banner banner) {
        WebKit.startPage();
        List<Banner> list = bannerService.selectBannerList(banner);
        return WebKit.getDataTable(list);
    }

    /**
     * 导出基础：banner图列表
     */
    @PreAuthorize("@ss.hasPermi('cms:banner:export')")
    @Log(title = "基础：banner图", businessType = BusinessTypeEnum.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(Banner banner) {
        List<Banner> list = bannerService.selectBannerList(banner);
        ExcelUtil<Banner> util = new ExcelUtil<Banner>(Banner.class);
        return util.exportExcel(list, "banner");
    }

    /**
     * 获取基础：banner图详细信息
     */
    @PreAuthorize("@ss.hasPermi('cms:banner:query')")
    @GetMapping(value = "/{bid}")
    public AjaxResult getInfo(@PathVariable("bid") Long bid) {
        return AjaxResult.success(bannerService.selectBannerById(bid));
    }

    /**
     * 新增基础：banner图
     */
    @PreAuthorize("@ss.hasPermi('cms:banner:add')")
    @Log(title = "基础：banner图", businessType = BusinessTypeEnum.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Banner banner) {
        return WebKit.toAjax(bannerService.insertBanner(banner));
    }

    /**
     * 修改基础：banner图
     */
    @PreAuthorize("@ss.hasPermi('cms:banner:edit')")
    @Log(title = "基础：banner图", businessType = BusinessTypeEnum.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Banner banner) {
        return WebKit.toAjax(bannerService.updateBanner(banner));
    }

    /**
     * 删除基础：banner图
     */
    @PreAuthorize("@ss.hasPermi('cms:banner:remove')")
    @Log(title = "基础：banner图", businessType = BusinessTypeEnum.DELETE)
    @DeleteMapping("/{bids}")
    public AjaxResult remove(@PathVariable Long[] bids) {
        return WebKit.toAjax(bannerService.deleteBannerByIds(bids));
    }

}